<template>
    <div class="input-item">
      <el-form :model="performanceForm" ref="performanceForm" :rules="rules" label-width="250px">
          <div class="parameType-wrap">
                <div class="parameType">
                    <div class="button">
                        <!-- <span class="title2"> 性能阈值参数</span> -->
                        <el-button style="float: right; padding:4px 8px;" type="primary" @click="operationClick('performanceForm')">确定</el-button>
                    </div>
                    <el-col :xs="24" :sm="24" :lg="24">
                        <el-form-item label="装置性能自检周期：" prop="check_dcd_perf_interval">
                            <el-input class="input-style" v-model="performanceForm.check_dcd_perf_interval"><span slot="append">秒</span></el-input>
                            <span class="tips-style">（配为0代表无效）</span>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="24" :lg="24">
                        <el-form-item label="CPU使用率连续：" class="flex-item">
                            <el-form-item  style="width:31.3%" prop="dcd_max_cpu_keep_times">
                                <el-input v-model="performanceForm.dcd_max_cpu_keep_times"><span slot="append">次</span></el-input>
                            </el-form-item>
                            <span style="margin:0 0.7%">超过</span>
                            <el-form-item  style="width:32%" prop="dcd_max_cpu_percent">
                                <el-input max="100" v-model="performanceForm.dcd_max_cpu_percent"><span slot="append">%</span></el-input>
                            </el-form-item>
                            <span class="tips-style">（配为0代表无效）</span>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="24" :lg="24">
                        <el-form-item label="内存使用率连续：" class="flex-item">
                            <el-form-item  style="width:31.3%" prop="dcd_max_mem_keep_times">
                                <el-input v-model="performanceForm.dcd_max_mem_keep_times"><span slot="append">次</span></el-input>
                            </el-form-item>
                            <span style="margin:0 0.7%">超过</span>
                            <el-form-item  style="width:32%" prop="dcd_max_mem_percent">
                                <el-input max="100" v-model="performanceForm.dcd_max_mem_percent"><span slot="append">%</span></el-input>
                            </el-form-item>
                            <span class="tips-style">（配为0代表无效）</span>
                        </el-form-item>
                    </el-col>
                    
                    <el-col :xs="24" :sm="24" :lg="24">
                        <el-form-item label="磁盘空间阈值：" prop="dcd_max_disk_percent">
                            <el-input class="input-style" v-model="performanceForm.dcd_max_disk_percent"><span slot="append">%</span></el-input>
                            <span class="tips-style">（配为0代表无效）</span>
                        </el-form-item>
                    </el-col>
                </div>
          </div>    
      </el-form>
    </div>
</template>
  
<script>
import { connrequest } from '@/api/firstPage'
import { validNum } from '@/utils/validate'
export default {
    data() {
        return {
            performanceForm:{
                check_dcd_perf_interval:0,
                dcd_max_mem_keep_times:0,
                dcd_max_cpu_percent:0,
                dcd_max_cpu_keep_times:0,
                dcd_max_mem_percent:0,
                dcd_max_disk_percent:0
            },
            oldData:[],
            rules:{
                check_dcd_perf_interval:[{required:true,validator:validNum,trigger:'blur'}],
                dcd_max_mem_keep_times:[{required:true,validator:validNum,trigger:'blur'}],
                dcd_max_cpu_percent:[{required:true,validator:validNum,trigger:'blur'}],
                dcd_max_cpu_keep_times:[{required:true,validator:validNum,trigger:'blur'}],
                dcd_max_mem_percent:[{required:true,validator:validNum,trigger:'blur'}],
                dcd_max_disk_percent:[{required:true,validator:validNum,trigger:'blur'}]
            }
        }
    },
    created(){
    this.getData()
    // console.log();
    
    },
    methods:{
        async getData(){
            // const data = {}
            const res = await connrequest('GetParamThreshhold')
            // console.log(res.Data);
            this.oldData = res.Data;
            res.Data = res.Data.map(item => {
                for (const i in this.performanceForm) {
                    if (item.Name === i) {
                        this.performanceForm[i] = item.Value
                    }
                }
            })
        },
        async operationClick(formName){
            this.$refs[formName].validate(async(valid) => {
                if (valid) {
                this.oldData = this.oldData.map(item => {
                for (const key in this.performanceForm) {
                    if(item.Name === key){
                        if (typeof this.performanceForm[key] != 'string') {
                            item.Value = JSON.stringify(this.performanceForm[key])
                        }else{
                            item.Value = this.performanceForm[key]
                        }
                    }
                }
                    return item
                })
                const data = {
                    Data:this.oldData
                }
                const res = await connrequest('SetParamThreshhold',data)
                this.$message.success('修改成功')
                this.getData();
                }
            })
        }
    }
}
</script>

<style lang="scss" scoped>
/* @import url(); 引入css类 */
.parameType-wrap{
    display:flex;
    flex-wrap: wrap;
    margin-bottom: 20px;
}
::v-deep.input-item{
    // margin-top: 10px;
    .parameType{
    border: 1px solid #eceff5;
    border-radius: 3px;
    width: 800px;
    //   padding: 10px;
    margin: 0px;
    box-shadow: 0 0 10px #eceff5;
    .button{
        
        border-bottom: 1px solid #eceff5;
        padding-bottom : 32px;
    }
    }
    .el-form-item{
    margin-bottom: 6px;
    }
    .el-input-group__append, .el-input-group__prepend{
    width: 60px;
    padding: 0;
    text-align: center;
    }
}
.input-style{
    width: 70% !important;
}
.button{
    // display: flex;
    // justify-content: space-between;
    margin-bottom: 20px;
}
::v-deep.el-form-item{
    label{
    font-weight: 500;
    }
}
.flex-item{
    ::v-deep .el-form-item__content{
    display: flex;
    }
    .el-form-item {
    margin-bottom: 0px;
    }
} 
</style>